/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package wli.java.db;

import java.io.Serializable;
import java.util.ArrayList;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;

/**
 *
 * @author liw
 */
@ManagedBean
@SessionScoped
public class AssetController implements Serializable {

    private DataModel assetList;
    private AssetHelper assetHelper;
    private Asset assetCurrent;
    private int asset_id;
    private DataModel targetList;
    private TargetHelper targetHelper;
    private Target targetCurrent;
    private DataModel target_list;

    public AssetController() {
        assetHelper = new AssetHelper();
    }

    public AssetController(int asset_id) {
        assetHelper = new AssetHelper();
        asset_id = asset_id;
    }

    public DataModel getAssetList() {
        if (assetList == null) {
            assetList = new ListDataModel(assetHelper.getAssetList());
        }
        return assetList;
    }

    public DataModel getTargetList() {
        if (assetCurrent != null) {
            targetList = new ListDataModel(assetHelper.getTargetList(assetCurrent.getHostName()));
        }
        return targetList;
    }

    public DataModel getTargetListByFindingId() {
        if (targetCurrent != null) {
            target_list = new ListDataModel(assetHelper.getTargetListByFindingId(targetCurrent.getId().getFindingId()));
        }
        return target_list;
    }

    public String prepareView() {
        assetCurrent = (Asset) getAssetList().getRowData();
        return "index3";
    }

    public String prepareViewTarget() {
        targetCurrent = (Target) getTargetList().getRowData();
        System.out.println("Finding ID  =================" + targetCurrent.getId().getFindingId());
        return "index3";
    }
}
